import axios from './axios'
import qs from 'qs'

// 获取编号
export function getRequestNo() {
    return axios.get('/spare_request/manage/get_request_no.do').then(res => Promise.resolve(res.data))
}

// save request
export function savePurchaseQuest(requestData) {
    let data = qs.stringify(requestData);
    return axios.post('/spare_request/manage/save_spare_request.do', data).then(res => Promise.resolve(res.data))
}

//confirm 
export function comfirmPurchaseQuest(requestData) {
    let data = qs.stringify(requestData);
    return axios.post('/spare_request/manage/confirm_spare_request.do', data).then(res => Promise.resolve(res.data))

}

//获取所有配件采购列表
export function getAllPartPurchaseList() {
    return axios.get('/spare_request/manage/get_spare_request_list.do').then(res => Promise.resolve(res.data))
}

//获取request 详情
export function getPartPurchaseRequestDetail(requestId) {
    let data = qs.stringify({requestId});
    return axios.post('/spare_request/manage/get_spare_request_detail.do', data).then(res => Promise.resolve(res.data))
}

//获取已经提交的
export function getSubmitedRequestList() {
    return axios.get('/spare_request/manage/get_approve_request_list.do').then(res => Promise.resolve(res.data))
}

//获取已经审核通过的

export function getApprovedRequestList() {
    return axios.get('/spare_request/manage/get_purchase_request_list.do').then(res => Promise.resolve(res.data))
}

// 获取采购单
export function getPurchaseOrder() {
    return axios.get('/spare_purchase/manage/get_spare_purchase_list.do').then(res => Promise.resolve(res.data))
}

export function submitPo({id, duty, freight, bagging, otherCost}) {
    return axios.post('/spare_purchase/manage/on_spare_purchase_order.do', qs.stringify({
        id,
        duty,
        freight,
        bagging,
        otherCost
    })).then(res => Promise.resolve(res.data))
}

// 获取采购单详情
export function getPoDetail(id) {
    return axios.post('/spare_purchase/manage/get_spare_purchase_detail.do', qs.stringify({purchaseId: id})).then(res => Promise.resolve(res.data))
}

//获取供应商历史Po
export function getPoHistory(id) {
    return axios.post('/spare_purchase/manage/get_supplier_purchase_list.do', qs.stringify({supplierId: id})).then(res => Promise.resolve(res.data))
}